package com.linkoog.devtools.code_generator.wizard.generate.database.table.dialog.datasource.panel;

import com.linkoog.devtools.code_generator.database.domain.DatabaseInfo;

import javax.swing.*;
import java.awt.*;

public class DatabaseComboBoxCellRender implements ListCellRenderer {

    private JLabel label;


    public DatabaseComboBoxCellRender() {
        label = new JLabel();
        label.setOpaque(true);
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if (value == null) {
            label.setText("");
            return label;
        }

        if (value instanceof DatabaseInfo){
            DatabaseInfo databaseInfo = (DatabaseInfo)value;
            label.setText(databaseInfo.databaseName);
        } else if (value instanceof CharSequence){
            label.setText(value.toString());
        } else if (value instanceof EmptyItem){
            EmptyItem emptyItem = (EmptyItem)value;
            label.setIcon(emptyItem.getIcon());
            label.setText(emptyItem.getText());
        }

        return label;
    }
}
